<%@page import="java.sql.*"%>
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Java测试题</title>
<style type="text/css">
h1{
	color: #ff9999;
	text-align: center;
}
.kuang{
	border: 3px solid #ffff99;
	background: #ffffcc;
	margin: auto;
	padding: 0px 20px;
	width: 700px;
	font-family: monospace;
}
.timu{
	border: 2px solid #ffcc99;
	border-radius: 15px;
	background: #ffcccc;
	margin: 20px 0px;
	padding: 20px;
	font-size: 20px;
}
.timu>div{
	display: flex;
	margin: 5px;
}
.timu>div pre{
	white-space: pre-wrap;
	word-break: break-all;
}
.timu>div:first-child{
	border: 2px dotted #669;
	border-radius: 10px;
	padding: 20px;
}
.timu>div:first-child b{
	width: 50px;
	text-align: right;
}
.timu>div:nth-child(n+2){
	border-radius: 10px;
	padding: 10px 0 10px 72px;
}
.timu>div pre{
	margin: 0;
}
.da{
	background-color: #00f2;
}
.nav{
	text-align: center;
}
.nav a{
	color: gray;
	text-decoration: none;
	font-size: 30px;
}
.nav a:hover{
	color: red;
}
.nav b{
	color: red;
	font-size: 30px;
}
</style>
</head>
<body>
<h1>Java测试题</h1>
<div class="kuang">
<%
String url="jdbc:mysql://localhost:3306/db?serverTimezone=PRC";
//(1)加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//(2)创建连接
Connection cn = DriverManager.getConnection(url,"root","12qwas");
//(3)创建sql插入语句并设定参数的值
PreparedStatement ps = cn.prepareStatement("select count(*) from ku");
ResultSet rs = ps.executeQuery();
rs.next();
int tmshu=rs.getInt(1);//题目数
int tpage=5;//每页题目数
int maxPage=tmshu/tpage+(tmshu%tpage==0?0:1);
int n=4;
String sym=request.getParameter("page");
if(sym==null)sym="1";
int iym=Integer.parseInt(sym);
if(iym<1)iym=1;
else if(iym>maxPage)iym=maxPage;
//out.print("当前页码："+iym);
int begin=iym-n;
int end=iym+n;
if(begin<1){
	begin=1;
	end=2*n+1;
	if(end>maxPage)end=maxPage;
}else if(end>maxPage){
	end=maxPage;
	begin=maxPage-2*n;
	if(begin<1)begin=1;
}

ps = cn.prepareStatement("select * from ku limit ?,?");
ps.setInt(1, (iym-1)*tpage);
ps.setInt(2, tpage);
rs = ps.executeQuery();
for(int bh=1;rs.next();++bh){
	String da=rs.getString("r");
	out.println("\t<div class='timu'>");
	out.println("\t\t<div><b>"+bh+"、</b><pre>"+rs.getString("t")+"</pre></div>");
	out.println("\t\t<div"+(da.equals("A")?" class='da'":"")+"><b>A、</b><pre>"+rs.getString("a")+"</pre></div>");
	out.println("\t\t<div"+(da.equals("B")?" class='da'":"")+"><b>B、</b><pre>"+rs.getString("b")+"</pre></div>");
	out.println("\t\t<div"+(da.equals("C")?" class='da'":"")+"><b>C、</b><pre>"+rs.getString("c")+"</pre></div>");
	out.println("\t\t<div"+(da.equals("D")?" class='da'":"")+"><b>D、</b><pre>"+rs.getString("d")+"</pre></div>");
	out.println("\t</div>");
}

out.println("\t<div class='nav'>");
for(int i=begin;i<=end;++i){
	if(i==iym)out.println("\t\t<b>"+i+"</b>");
	else out.println("\t\t<a href='?page="+i+"'>"+i+"</a>");
}
out.println("\t</div>");
%>
</div>
</body>
</html>